package com.me.chat.controller.suport;

import com.me.chat.pojo.suport.User;
import com.me.chat.util.SimpleUserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2RefreshToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * token处理的controller
 * @Authhor: qiu
 * @Date: 2021/11/16 9:37 下午
 */
@RestController
@RequestMapping("/res/token")
@Slf4j
public class TokenManageController {

    @Autowired
    TokenStore tokenStore;

    /**
     * 退出登录
     * @param request
     */
    @GetMapping("/logout")
    public void logout(HttpServletRequest request) {
        //从请求头中获取token
        String token = SimpleUserInfo.getTokenFromHeader(request);

        //清空redis 中 token 的信息
        OAuth2AccessToken accessToken = tokenStore.readAccessToken(token);
        tokenStore.removeAccessToken(accessToken);
        log.info("token:"+token+"已经删除");
    }
}
